@extends('layout.adminlayout')
@section('css')
 <script src="/admin/js/metisMenu.min.js"></script>
 <script src="/admin/js/custom.js"></script>
 <link href="/admin/css/area_info.css" rel="stylesheet">
 <link href="/admin/css/custom.css" rel="stylesheet">
 <link href="/admin/css/add_manage.css" rel="stylesheet">
 <link href="/admin/css/select_building.css" rel="stylesheet">
@endsection
@section('content')
     <div class="forms"> 
      <div class=" form-grids row form-grids-right"> 
       <div class="widget-shadow " data-example-id="basic-forms"> 
        <div class="form-title"> 
         <h4>添加位置 :</h4> 
        </div> 
        <div class="form-body"> 
         <form action="/admin/building/store" method="post" class="form-horizontal" onsubmit="return fun4()">
          {{csrf_field()}}
          <div class="form-group"> 
           <label for="inputEmail3" class="col-sm-2 control-label" style="width:33%;float: left;top: 30px;"> 所属区域 : </label> 
           <li class="area_info"> 
            <div class="col-sm-6"> 
             <select name="area" id="area" class="form-control1" style="width: 70%;float: right;">
              <option value="0">请选择区域</option>
              @if($area != null)
               @foreach($area as $v)
                <option value="{{$v['a_id']}}">{{$v['a_name']}}</option>
               @endforeach
              @endif
             </select>
            </div> 
            </li> 
          </div> 
          <div class="form-group"> 
           <label for="inputEmail3" class="col-sm-2 control-label" style="width:33%;float: left;    top: 26px;"> 建筑 : </label> 
           <li class="area_info"> 
            <div class="col-sm-3"> 
             <select name="building" id="building" class="form-control1" style="width: 70%;float: right;"> <option value="0">请选择建筑</option> </select> 
            </div> 
            </li> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-2 control-label" style="width:33%;float: left;    top: 30px;"> 房间名称 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="room" id="room" placeholder="房间名称" style="width: 70%;float: right;" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-2 control-label" style="width:33%;float: left;    top: 30px;"> 所在楼层 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="floor" id="floor" placeholder="所在楼层" style="width: 70%;float: right;" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-2 control-label"> </label> 
           <ul id="ul"> 
           </ul> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-2 control-label" style="width:33%;float: left; top:6px;"> 负责人 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="manage" placeholder="负责人" id="manage" style="width: 31%;float: left;margin-left: -3px;" /> 
            <button type="button" class="btn btn-default" id="add" style="float: right">添加</button> 
           </div> 
          </div> 
          <div class="col-sm-offset-2"> 
           <button type="button" class="btn btn-default" id="sub" style="margin-left: -22px; width: 90%">提交</button> 
          </div> 
         </form> 
        </div> 
       </div> 
      </div> 
     </div> 
     <script>
	//区域建筑联动
	$('#area').change(function () {
		var areaId = $('#area').val();
		var dd = '<option class="dstyle" value="">请选择建筑</option>';
		$.ajax({
			type:'post',
			url:'/admin/room/getbuild',
            async:false,
            data:{
                "_token": $("input[name=_token]").val(),
                'areaId':areaId,
            },
            dataType:'json',
            success:function (data) {
                for(var i=0;i<data.length;i++){
                    dd += '<option class="dstyle" value="'+data[i]['b_id']+'">'+data[i]['b_name']+'</option>';
				}
                $('#building').empty();
                $('#building').append(dd);
            }
		})
    })
    //提交表单
    $('#sub').click(function () {
        var area = $('#area').val();
        var building = $('#building').val();
        var room = $('#room').val();
        var floor = $('#floor').val();
        var manage = new Array();
        $('.mng').each(function () {
            manage.push($(this).html());
        });
        if(area != 0 && building != 0 && room != '' && floor != ''){
            $.ajax({
                type:'post',
                url:'/admin/room/create',
                async:false,
                data:{
                    "_token": $("input[name=_token]").val(),
                    'area':area,
					'building':building,
					'room':room,
					'floor':floor,
                    'manage':manage
                },
                dataType:'json',
                success:function (data) {
                    if(data.status == '1'){
                        location.href = '/admin/room/index';
                    }
                    return false;
                }
            })
        }else{
            alert('信息填写不完整')
            return false;
        }
    });
</script>
@endsection
@section('lastjs')
 <script src="/admin/js/add_manage.js"></script>
 <script src="/admin/js/select_building.js"></script>
@endsection